﻿using System;
using Microsoft.Extensions.DependencyInjection;

namespace netCoreStudy.Extensions
{
	/// <summary>
	/// 跨域服务 设置
	/// </summary>
	public static class CorsSetup
	{
		public static void AddCorsSetup(this IServiceCollection services, string CorsOrigins)
		{
			if (services == null) throw new ArgumentNullException(nameof(services));
			services.AddCors(options =>
			{
				options.AddPolicy(CorsOrigins,
					builder =>
					{
						builder
							.SetIsOriginAllowed(x => true)
							.AllowAnyHeader()
							.AllowAnyMethod()
							.AllowCredentials()
							;
					});
			});
		}
	}
}